package com.kai.controller;

import com.kai.dto.CommentDTO;
import com.kai.dto.CourierPickUpDTO;
import com.kai.dto.ExpressOrderQueryDTO;
import com.kai.result.PageResult;
import com.kai.result.Result;
import com.kai.service.CourierService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@Slf4j
@RequestMapping("/express/courier")
@Tag(name = "快递员接单相关接口")
public class CourierController {

    @Autowired
    private CourierService courierService;

    @Operation(summary = "分页查询所有待接单订单 接口")
    @GetMapping("/queryAll")
    public Result<PageResult> queryAllOrders(ExpressOrderQueryDTO expressOrderQueryDTO) {
        log.info("分页查询所有订单 {}", expressOrderQueryDTO);
        PageResult expressOrderVOList = courierService.queryAllOrders(expressOrderQueryDTO);
        return Result.success(expressOrderVOList);
    }

    //todo websocket 通知下单的人 快递员已接单
    @Operation(summary = "接单 接口")
    @PutMapping("/accept")
    public Result<Void> acceptOrder(@RequestBody CourierPickUpDTO courierPickUpDTO) {
        log.info("接单 {}", courierPickUpDTO);
        courierService.acceptOrder(courierPickUpDTO);
        return Result.success();
    }

    @Operation(summary = "获取接单员status 接口")
    @GetMapping("/status")
    public Result<Long> getStatus(Long courierId) {
        log.info("获取接单员status");
        Long status = courierService.getStatus(courierId);
        return Result.success(status);
    }


    @Operation(summary = "分页查询所有快递员已接单订单 接口")
    @GetMapping("/queryAllAccepted")
    public Result<PageResult> queryAllAcceptedOrders(ExpressOrderQueryDTO expressOrderQueryDTO) {
        log.info("分页查询所有快递员已接单订单");
        log.info("分页查询>: {}", expressOrderQueryDTO);
        PageResult expressOrderVOList = courierService.queryAllAcceptedOrders(expressOrderQueryDTO);
        return Result.success(expressOrderVOList);
    }

    //todo websocket 通知下单的人 快递员已取件
    @Operation(summary = "快递员确认取件 接口")
    @PutMapping("/pickUp")
    public Result<Void> pickUp(CourierPickUpDTO courierPickUpDTO) {
        log.info("快递员确认取件 {}", courierPickUpDTO);
        courierService.pickUp(courierPickUpDTO);
        return Result.success();
    }

    //todo websocket 通知下单的人 快递已送达
    @Operation(summary = "快递员确认送达 接口")
    @PutMapping("/delivered")
    public Result<Void> deliver(CourierPickUpDTO courierPickUpDTO) {
        log.info("快递员确认送达 {}", courierPickUpDTO);
        courierService.deliver(courierPickUpDTO);
        return Result.success();
    }


    @Operation(summary = "评价接口")
    @PostMapping("/comment")
    public Result<Void> comment(@RequestBody CommentDTO commentDTO) {
        log.info("评价 {}", commentDTO);
        courierService.comment(commentDTO);
        return Result.success();
    }


}
